From 0f84963214ee6dc5b5a44d945540826a66bec9e0 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Wed, 11 Dec 2024 11:51:45 +0700
Subject: <iman> update pengajuan tempo

---
 src/pages/pengajuan-tempo/[status].jsx | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

(limited to 'src/pages/pengajuan-tempo/[status].jsx')

diff --git a/src/pages/pengajuan-tempo/[status].jsx b/src/pages/pengajuan-tempo/[status].jsx
index 1ebf167b..c97b5897 100644
--- a/src/pages/pengajuan-tempo/[status].jsx
+++ b/src/pages/pengajuan-tempo/[status].jsx
@@ -3,7 +3,9 @@ import IsAuth from '@/lib/auth/components/IsAuth';
 import FinishTempoComponent from '@/lib/pengajuan-tempo/component/FinishTempo';
 import { useRouter } from 'next/router';
 import axios from 'axios';
+import { useState, useEffect } from 'react';
 import Seo from '@/core/components/Seo';
+import { getAuth } from '~/libs/auth';
 
 export async function getServerSideProps(context) {
   const { tempo_id } = context.query;
@@ -16,8 +18,26 @@ export async function getServerSideProps(context) {
 }
 
 export default function Finish() {
+  const [isLoading, setIsLoading] = useState(true);
   const router = useRouter();
+  const auth = getAuth();
+  useEffect(() => {
+    if (!auth) {
+      const nextUrl = encodeURIComponent(router.asPath);
+      router.push(`/login?next=${nextUrl}`);
+    } else if (
+      (router.query.status == 'approve' || router.query.status == 'review') &&
+      auth.tempoProgres === ''
+    ) {
+      router.push('/pengajuan-tempo');
+    } else {
+      setIsLoading(false);
+    }
+  }, [auth]);
 
+  if (isLoading || !auth) {
+    return null; // Tidak render apa pun selama loading atau auth/tempo belum tersedia
+  }
   return (
     <>
       <Seo title='Pengajuan Tempo Indoteknik.com' />
-- 
cgit v1.2.3

